package com.example.e_comm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.e_comm.entity.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {
    // 根据用户获取角色列表

    @Select("SELECT *FROM permissions p"
            +"INNER JOIN role_permission rp ON p.id = rp.perm_id"
            +"INNER JOIN user_role ur ON rp.role_id = ur.role_id"
            +"WHERE p.deleted = 0 AND ur.user_id = #{userId}")
    List<Permission> getPermissionsByUserId(@Param("userId")Long userId);

    //根据角色获取其角色列表
    @Select("SELECT * FROM permissions p"+
            "INNER JOIN role_permission rp ON p.id = rp.perm_id"+
            "WHERE rp.role_id = #{roleId} AND p.deleted = 0")
    List<Permission> getPermissionsByRoleId(@Param("roleId")Long roleId);


}

